home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / editor.cpp < prev    next >
C/C++ Source or Header  |  1996-02-21  |  24KB  |  1,111 lines

  1. #include "global.h"
  2. #include "mouse.h"
  3.  
  4. /******************************************************************************
  5. ******************************************************************************/
  6.  
  7. #define TRUE 1
  8. #define FALSE 0
  9.  
  10. /******************************************************************************
  11. *****************************************************************************/
  12.  
  13. // EDITOR GLOBAL VARIABLES...
  14.  
  15. int e_button_lit=0;
  16. int ed_zone=0;
  17. int ed_poss=0;
  18. int ed_last_poss=0;
  19. int ed_last_zone=0;
  20. int picked_up=0;
  21. char tac_buffer[((32*2)+4)*10*2*5];
  22.  
  23. int temp_tactic[10][2];
  24. int undo_tactic[10][2];
  25. int ed_tactic[(32*2)+6][10][2];        //Current Tactic Buffer.
  26. char tac_name[9]="new_tacs";
  27.  
  28. struct buttons {
  29.     int x;
  30.     int y;
  31.     int w;
  32.     char s[10];
  33.     char l;
  34. };
  35.  
  36. buttons ed_buttons[]={{186,12,1,"C",0},{292,12,1,"C",0},
  37.                             {186,90,1,"C",0},{292,90,1,"C",0},
  38.                             {12,120,4,"LOAD",0},{60,120,4,"SAVE",0},
  39.                             {220,98,6,"POSS ",0},{192+12,132,4,"COPY",0},
  40.                             {240+12,132,4,"SWAP",0},{192+12,156,4,"UNDO",0},
  41.                             {240+12,156,4,"INIT",0},{320-40,200-16,4,"GAME",0},
  42.                              {108,120,4,"NAME",0},{186,42,1,"K",0},{292,42,1,"K",0}};
  43.  
  44. int max_buttons=(sizeof(ed_buttons)/sizeof(buttons));
  45.  
  46. /******************************************************************************
  47. *****************************************************************************/
  48.  
  49. // EDITOR FUNCTIONS...
  50.  
  51. /******************************************************************************
  52. *****************************************************************************/
  53.  
  54. float rem(float n,int d)
  55. {
  56.     return((n/d)-((int)n/d));
  57. }
  58.  
  59. /******************************************************************************
  60. *****************************************************************************/
  61.  
  62. void e_line_border(int x,int y,int wid,int hgt,int col)
  63. {
  64.     int c=_getcolor();
  65.     _moveto(x,y);
  66.     _setcolor(col);
  67.     _lineto(x+wid-1,y);
  68.     _lineto(x+wid-1,y+hgt-1);
  69.     _lineto(x,y+hgt-1);
  70.     _lineto(x,y);
  71.     _setcolor(c);
  72. }
  73.  
  74. /******************************************************************************
  75. *****************************************************************************/
  76.  
  77. void draw_grid()
  78. {
  79.     _setcolor(4);
  80.     float step=(160.2)/7;
  81.     float x=8+(step/2);
  82.     for (int i=1; i<8; i++, x+=step )
  83.     {
  84.         _moveto((int)x,8);
  85.         _lineto((int)x,108);
  86.     }
  87.     step=100/3;
  88.     x=8+(step/2);
  89.     for (i=1; i<4; i++, x+=step )
  90.     {
  91.         _moveto(8,(int)x);
  92.         _lineto(168,(int)x);
  93.     }
  94. }
  95.  
  96. /******************************************************************************
  97. *****************************************************************************/
  98.  
  99. void draw_zones()
  100. {
  101.     _setcolor(7);
  102.     float step=(84)/7;
  103.     float x=200+(step/2);
  104.     for (int i=1; i<8; i++, x+=step )
  105.     {
  106.         _moveto((int)x,24);
  107.         _lineto((int)x,68+16);
  108.     }
  109.     step=60/3;
  110.     x=24+(step/2);
  111.     for (i=1; i<4; i++, x+=step )
  112.     {
  113.         _moveto(200,(int)x);
  114.         _lineto(200+84,(int)x);
  115.     }
  116.     e_line_border(200,24,85,61,7);
  117.     _moveto(216,12);
  118.     _outgtext("ZONE 1");
  119. }
  120.  
  121.  
  122. /******************************************************************************
  123. *****************************************************************************/
  124.  
  125. void draw_markings()
  126. {
  127.     _moveto(8,8);
  128.     _setcolor(7);
  129.     _lineto(168,8);
  130.     _lineto(168,108);
  131.     _lineto(8,108);
  132.     _lineto(8,8);
  133. // Left Goal
  134.     _moveto(7,50-5+7);
  135.     _lineto(4,50-5+7);
  136.     _lineto(4,50+5+7);
  137.     _lineto(7,50+5+7);
  138. // Right Goal
  139.     _moveto(161+8,50-5+7);
  140.     _lineto(165+8,50-5+7);
  141.     _lineto(165+8,50+5+7);
  142.     _lineto(161+8,50+5+7);
  143. // Left Six Yard Box
  144.     _moveto(8,50-13+7);
  145.     _lineto(8+8,50-13+7);
  146.     _lineto(8+8,50+13+7);
  147.     _lineto(8,50+13+7);
  148. // Right Six Yard Box
  149.     _moveto(160+8,50-13+7);
  150.     _lineto(160-8+8,50-13+7);
  151.     _lineto(160-8+8,50+13+7);
  152.     _lineto(160+8,50+13+7);
  153. // Left 18 Yard Box
  154.     _moveto(8,50-29+7);
  155.     _lineto(8+24,50-29+7);
  156.     _lineto(8+24,50+29+7);
  157.     _lineto(8,50+29+7);
  158. // Right 18 Yard Box
  159.     _moveto(160+8,50-29+7);
  160.     _lineto(160+8-24,50-29+7);
  161.     _lineto(160+8-24,50+29+7);
  162.     _lineto(160+8,50+29+7);
  163. // Centre circle
  164.     _ellipse(_GBORDER,80+8-13,50+7-13,80+8+13,50+7+13);
  165.     _setcolor(2);
  166.     _moveto(10,54);
  167.     _outgtext("1");
  168. }
  169.  
  170. /******************************************************************************
  171. *****************************************************************************/
  172.  
  173. void draw_edteam()
  174. {
  175.     char st[3];
  176.     int x,y;
  177.     int c=_getcolor();
  178.     int p=_getplotaction();
  179.     _setcolor(2);
  180.     _setplotaction(_GXOR);
  181.     for (int i=0; i<10; i++)
  182.     {
  183.         sprintf(st,"%d",i+2);
  184.         x=(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][0])/8;
  185.         y=(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][1])/8;
  186.         _moveto(8+x-3,8+y-3);
  187.         HideMouse();
  188.         _outgtext(st);
  189.         ShowMouse();
  190.     }
  191.     _setplotaction(p);
  192.     _setcolor(c);
  193. }
  194.  
  195. /******************************************************************************
  196. *****************************************************************************/
  197.  
  198. void e_draw_buttons()
  199. {
  200.     int x,y,w;
  201.     char st[10];
  202.     for (int i=0; i<max_buttons; i++)
  203.     {
  204.         x=ed_buttons[i].x;
  205.         y=ed_buttons[i].y;
  206.         w=ed_buttons[i].w;
  207.         strcpy(st,ed_buttons[i].s);
  208.         _moveto(x,y);
  209.         _outgtext(st);
  210.         e_line_border(x-4,y-4,w*8+8,16,1);
  211.     }
  212. }
  213.  
  214. /******************************************************************************
  215. *****************************************************************************/
  216.  
  217. void e_light_button(int b)
  218. {
  219.     int x,y,w,c;
  220.     c=_getcolor();
  221.     char st[10];
  222.     x=ed_buttons[b].x;
  223.     y=ed_buttons[b].y;
  224.     w=ed_buttons[b].w;
  225.     strcpy(st,ed_buttons[b].s);
  226.     _setcolor(7);
  227.     _moveto(x,y);
  228.     HideMouse();
  229.     _outgtext(st);
  230.     _setcolor(c);
  231.     ShowMouse();
  232.     e_button_lit=b+1;
  233. }
  234.  
  235. /******************************************************************************
  236. *****************************************************************************/
  237.  
  238. void e_unlight_button(int b)
  239. {
  240.     int x,y,w;
  241.     char st[10];
  242.     x=ed_buttons[b].x;
  243.     y=ed_buttons[b].y;
  244.     w=ed_buttons[b].w;
  245.     strcpy(st,ed_buttons[b].s);
  246.     _moveto(x,y);
  247.     HideMouse();
  248.     _outgtext(st);
  249.     ShowMouse();
  250.     if (e_button_lit==b+1)
  251.         e_button_lit=0;
  252. }
  253. /******************************************************************************
  254. *****************************************************************************/
  255.  
  256. void e_process_butts()
  257. {
  258.     int x,y,w;
  259.     for (int i=0; i<max_buttons; i++)
  260.     {
  261.         x=ed_buttons[i].x;
  262.         y=ed_buttons[i].y;
  263.         w=ed_buttons[i].w;
  264.         if ((Mouse.x/2>=x-4) && (Mouse.x/2<=x+(w*8)+4)
  265.             && (Mouse.y>=y-4) && (Mouse.y<=y+12))
  266.         {
  267.             if (!ed_buttons[i].l)
  268.             {
  269.                 e_light_button(i);            //Mouse will highlight button.
  270.                 ed_buttons[i].l=1;
  271.             }
  272.         }
  273.         else
  274.         {
  275.             if (ed_buttons[i].l)
  276.             {
  277.                 e_unlight_button(i);
  278.                 ed_buttons[i].l=0;
  279.             }
  280.         }
  281.     }
  282. }        
  283.  
  284. /******************************************************************************
  285. *****************************************************************************/
  286.  
  287. void undo_copy()
  288. {
  289.     memcpy(undo_tactic,ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],10*2*sizeof(int));
  290. }
  291.  
  292.  
  293. /******************************************************************************
  294. *****************************************************************************/
  295.  
  296. void reset_poss()
  297. {
  298.     ed_last_poss=ed_poss;
  299. }
  300.  
  301. /******************************************************************************
  302. *****************************************************************************/
  303.  
  304. void init_zgrid()
  305. {
  306.          _setplotaction(_GXOR);
  307.         ed_zone=0;
  308.         undo_copy();
  309.         _moveto(200-3,24-3);
  310.         HideMouse();
  311.         int c=_getcolor();
  312.         _setcolor(7);
  313.         _outgtext("O");
  314.         ShowMouse();
  315.          _setplotaction(_GPSET);
  316.         _setcolor(c);
  317. }
  318.  
  319. /******************************************************************************
  320. *****************************************************************************/
  321.  
  322. void write_name()
  323. {
  324.     _moveto(8,184);
  325.     int c=_getcolor();
  326.     int g=_getplotaction();
  327.     _setplotaction(_GXOR);
  328.     _setcolor(3);
  329.     _outgtext(tac_name);
  330.     _setcolor(c);
  331.     _setplotaction(g);
  332. }
  333.  
  334. /******************************************************************************
  335. *****************************************************************************/
  336.  
  337. void input_keys(char *i,int chars)
  338. {
  339.     char buff[2+41];
  340.     int n=chars;
  341.     if (!n)
  342.         n=8+1;        // filename.
  343.     buff[0]=n;
  344.     cgets(buff);
  345.     strcpy(i,buff+2);
  346. }
  347.  
  348. /******************************************************************************
  349. *****************************************************************************/
  350.  
  351. void name_butt()
  352. {
  353.     write_name();
  354.     _settextposition(24,2);
  355.     _outtext("New name: ");
  356.     input_keys(tac_name,0);        //0=filename.
  357.     _settextposition(24,2);
  358.     _outtext("                      ");
  359.     write_name();
  360. }
  361.  
  362. /******************************************************************************
  363. *****************************************************************************/
  364.  
  365. void save_butt()
  366. {
  367.     write_name();
  368.     _settextposition(24,2);
  369.     _outtext("Are you sure(Y/N)?");
  370.     char k;
  371.     do
  372.     {
  373.         k=getch();
  374.     } while(k!='y' && k!='n');
  375.     if (k=='y')
  376.     {
  377.         _settextposition(24,2);
  378.         _outtext("                      ");
  379.         _settextposition(24,2);
  380.         _outtext("Saving: ");
  381.         char file_name[13];
  382.         strcpy(file_name,tac_name);
  383.         strcat(file_name,".tac");
  384.         _outtext(file_name);
  385.          FILE *fp1=fopen(file_name,"wb");
  386.         if (fp1==0)
  387.         {
  388.             _settextposition(24,2);
  389.             _outtext("Save Failed");
  390.             delay(1200);
  391.         }
  392.         else
  393.         {
  394.             fwrite(ed_tactic,sizeof(int),((32*2)+6)*10*2,fp1);
  395.             fclose(fp1);
  396.             delay(600);
  397.         }
  398.     }
  399.     _settextposition(24,2);
  400.     _outtext("                      ");
  401.     write_name();
  402. }        
  403.  
  404. /******************************************************************************
  405. *****************************************************************************/
  406.  
  407. void load_butt()
  408. {
  409.     draw_edteam();
  410.     write_name();
  411.     _settextposition(24,2);
  412.     _outtext("Are you sure(Y/N)?");
  413.     char k;
  414.     do
  415.     {
  416.         k=getch();
  417.     } while(k!='y' && k!='n');
  418.     if (k=='y')
  419.     {
  420.         _settextposition(24,2);
  421.         _outtext("                      ");
  422.         _settextposition(24,2);
  423.         _outtext("Loading: ");
  424.         char file_name[13];
  425.         strcpy(file_name,tac_name);
  426.         strcat(file_name,".tac");
  427.         _outtext(file_name);
  428.          FILE *fp1=fopen(file_name,"rb");
  429.         if (fp1==0)
  430.         {
  431.             _settextposition(24,2);
  432.             _outtext("Load Failed");
  433.             delay(1200);
  434.         }
  435.         else
  436.         {
  437.             fread(ed_tactic,sizeof(int),((32*2)+6)*10*2,fp1);
  438.             fclose(fp1);
  439.             delay(600);
  440.         }
  441.     }
  442.     _settextposition(24,2);
  443.     _outtext("                      ");
  444.     write_name();
  445.     draw_edteam();
  446. }        
  447.  
  448. /******************************************************************************
  449. *****************************************************************************/
  450.  
  451. void get_zx_zy(int *zx,int *zy)
  452. {
  453.         switch(ed_zone)
  454.         {
  455.             case 32+32:
  456.             {                  // top left corner.
  457.                 *zx=1;
  458.                 *zy=-9;
  459.                 break;
  460.             }
  461.  
  462.             case 32+33:
  463.             {                  // top right corner.
  464.                 *zx=84;
  465.                 *zy=-9;
  466.                 break;
  467.             }
  468.  
  469.             case 32+34:
  470.             {                  // bot left corner.
  471.                 *zx=1;
  472.                 *zy=70-1;
  473.                 break;
  474.             }
  475.  
  476.             case 32+35:
  477.             {                  // bot right corner.
  478.                 *zx=84;
  479.                 *zy=70-1;
  480.                 break;
  481.             }
  482.  
  483.             case 32+36:
  484.             {                  // home centre.
  485.                 *zx=-11;
  486.                 *zy=35;
  487.                 break;
  488.             }
  489.  
  490.             case 32+37:
  491.             {                  // away centre.
  492.                 *zx=95;
  493.                 *zy=35;
  494.                 break;
  495.             }
  496.  
  497.  
  498.             default:
  499.             {
  500.                 *zy=(ed_zone/8)*20;
  501.                 *zx=rem(ed_zone,8)*12*8;
  502.             }
  503.         }
  504. }
  505.     
  506. /******************************************************************************
  507. *****************************************************************************/
  508.  
  509. void zone_grid()
  510. {
  511.     int c=_getcolor();
  512.     _setcolor(7);
  513.     int x=(Mouse.x/2)-200;
  514.     int y=(Mouse.y-24);
  515.     x=((x+6)/12);
  516.     y=((y+10)/20);
  517.     int zone=x+(y*8);
  518.     if (zone!=ed_zone)
  519.     {
  520.         reset_poss();
  521.         _setplotaction(_GXOR);
  522.         char st[5];
  523.         int zx,zy;
  524.         get_zx_zy(&zx,&zy);            
  525.         _moveto(200-3+zx,24-3+zy);
  526.         HideMouse();
  527.         _outgtext("O");
  528.         _moveto(256,12);
  529.         sprintf(st,"%d",ed_zone+1);
  530.         _outgtext(st);
  531.         draw_edteam();
  532.  
  533.         ed_last_zone=ed_zone;
  534.         ed_zone=zone;
  535.         undo_copy();
  536.         zy=(ed_zone/8)*20;
  537.         zx=rem(ed_zone,8)*12*8;
  538.         _moveto(200-3+zx,24-3+zy);
  539.         _outgtext("O");
  540.         _moveto(256,12);
  541.         sprintf(st,"%d",ed_zone+1);
  542.         _outgtext(st);
  543.          _setplotaction(_GPSET);
  544.         ShowMouse();
  545.         draw_edteam();
  546.     }
  547.     _setcolor(c);
  548. }
  549.  
  550.  
  551.  
  552. /******************************************************************************
  553. *****************************************************************************/
  554.  
  555. void top_l_corn()
  556. {
  557.     reset_poss();
  558.     if (ed_zone!=32*2)
  559.     {    int c=_getcolor();
  560.         _setcolor(7);
  561.          _setplotaction(_GXOR);
  562.         char st[5];
  563.         int zx,zy;
  564.         get_zx_zy(&zx,&zy);
  565.         _moveto(200-3+zx,24-3+zy);
  566.         HideMouse();
  567.         _outgtext("O");
  568.  
  569.         _moveto(256,12);
  570.         sprintf(st,"%d",ed_zone+1);
  571.         _outgtext(st);
  572.         draw_edteam();
  573.  
  574.         ed_last_zone=ed_zone;
  575.         ed_zone=32*2;
  576.         _moveto(200-2,16-4);
  577.         _outgtext("O");
  578.  
  579.         _moveto(256,12);
  580.         sprintf(st,"%d",ed_zone+1);
  581.         _outgtext(st);
  582.          _setplotaction(_GPSET);
  583.         ShowMouse();
  584.         draw_edteam();
  585.         _setcolor(c);
  586.     }
  587. }        
  588.  
  589. /******************************************************************************
  590. *****************************************************************************/
  591.  
  592. void top_r_corn()
  593. {
  594.     reset_poss();
  595.     if (ed_zone!=1+(32*2))
  596.     {    int c=_getcolor();
  597.         _setcolor(7);
  598.          _setplotaction(_GXOR);
  599.         char st[5];
  600.         int zx,zy;
  601.         get_zx_zy(&zx,&zy);
  602.         _moveto(200-3+zx,24-3+zy);
  603.         HideMouse();
  604.         _outgtext("O");
  605.  
  606.         _moveto(256,12);
  607.         sprintf(st,"%d",ed_zone+1);
  608.         _outgtext(st);
  609.         draw_edteam();
  610.  
  611.         ed_last_zone=ed_zone;
  612.         ed_zone=1+(32*2);
  613.         _moveto(284-3,16-4);
  614.         _outgtext("O");
  615.  
  616.         _moveto(256,12);
  617.         sprintf(st,"%d",ed_zone+1);
  618.         _outgtext(st);
  619.          _setplotaction(_GPSET);
  620.         ShowMouse();
  621.         draw_edteam();
  622.         _setcolor(c);
  623.     }
  624. }        
  625.  
  626. /******************************************************************************
  627. *****************************************************************************/
  628.  
  629. void bot_l_corn()
  630. {
  631.     reset_poss();
  632.     if (ed_zone!=2+(32*2))
  633.     {    int c=_getcolor();
  634.         _setcolor(7);
  635.          _setplotaction(_GXOR);
  636.         char st[5];
  637.         int zx,zy;
  638.         get_zx_zy(&zx,&zy);
  639.         _moveto(200-3+zx,24-3+zy);
  640.         HideMouse();
  641.         _outgtext("O");
  642.  
  643.         _moveto(256,12);
  644.         sprintf(st,"%d",ed_zone+1);
  645.         _outgtext(st);
  646.         draw_edteam();
  647.  
  648.         ed_last_zone=ed_zone;
  649.         ed_zone=2+(32*2);
  650.         _moveto(200-2,94-4);
  651.         _outgtext("O");
  652.  
  653.         _moveto(256,12);
  654.         sprintf(st,"%d",ed_zone+1);
  655.         _outgtext(st);
  656.          _setplotaction(_GPSET);
  657.         ShowMouse();
  658.         draw_edteam();
  659.         _setcolor(c);
  660.     }
  661. }        
  662.  
  663. /******************************************************************************
  664. *****************************************************************************/
  665.  
  666. void bot_r_corn()
  667. {
  668.     reset_poss();
  669.     if (ed_zone!=3+(32*2))
  670.     {    int c=_getcolor();
  671.         _setcolor(7);
  672.          _setplotaction(_GXOR);
  673.         char st[5];
  674.         int zx,zy;
  675.         get_zx_zy(&zx,&zy);
  676.         _moveto(200-3+zx,24-3+zy);
  677.         HideMouse();
  678.         _outgtext("O");
  679.  
  680.         _moveto(256,12);
  681.         sprintf(st,"%d",ed_zone+1);
  682.         _outgtext(st);
  683.         draw_edteam();
  684.  
  685.         ed_last_zone=ed_zone;
  686.         ed_zone=3+(32*2);
  687.         _moveto(284-3,94-4);
  688.         _outgtext("O");
  689.  
  690.         _moveto(256,12);
  691.         sprintf(st,"%d",ed_zone+1);
  692.         _outgtext(st);
  693.          _setplotaction(_GPSET);
  694.         ShowMouse();
  695.         draw_edteam();
  696.         _setcolor(c);
  697.     }
  698. }
  699.  
  700. /******************************************************************************
  701. *****************************************************************************/
  702.  
  703. void home_centre()
  704. {
  705.     reset_poss();
  706.     if (ed_zone!=4+(32*2))
  707.     {    int c=_getcolor();
  708.         _setcolor(7);
  709.          _setplotaction(_GXOR);
  710.         char st[5];
  711.         int zx,zy;
  712.         get_zx_zy(&zx,&zy);
  713.         _moveto(200-3+zx,24-3+zy);
  714.         HideMouse();
  715.         _outgtext("O");
  716.  
  717.         _moveto(256,12);
  718.         sprintf(st,"%d",ed_zone+1);
  719.         _outgtext(st);
  720.         draw_edteam();
  721.  
  722.         ed_last_zone=ed_zone;
  723.         ed_zone=4+(32*2);
  724.         _moveto(189-3,60-4);
  725.         _outgtext("O");
  726.  
  727.         _moveto(256,12);
  728.         sprintf(st,"%d",ed_zone+1);
  729.         _outgtext(st);
  730.          _setplotaction(_GPSET);
  731.         ShowMouse();
  732.         draw_edteam();
  733.         _setcolor(c);
  734.     }
  735. }
  736.  
  737. /******************************************************************************
  738. *****************************************************************************/
  739.  
  740. void away_centre()
  741. {
  742.     reset_poss();
  743.     if (ed_zone!=5+(32*2))
  744.     {    int c=_getcolor();
  745.         _setcolor(7);
  746.          _setplotaction(_GXOR);
  747.         char st[5];
  748.         int zx,zy;
  749.         get_zx_zy(&zx,&zy);
  750.         _moveto(200-3+zx,24-3+zy);
  751.         HideMouse();
  752.         _outgtext("O");
  753.  
  754.         _moveto(256,12);
  755.         sprintf(st,"%d",ed_zone+1);
  756.         _outgtext(st);
  757.         draw_edteam();
  758.  
  759.         ed_last_zone=ed_zone;
  760.         ed_zone=5+(32*2);
  761.         _moveto(295-3,60-4);
  762.         _outgtext("O");
  763.  
  764.         _moveto(256,12);
  765.         sprintf(st,"%d",ed_zone+1);
  766.         _outgtext(st);
  767.          _setplotaction(_GPSET);
  768.         ShowMouse();
  769.         draw_edteam();
  770.         _setcolor(c);
  771.     }
  772. }
  773.  
  774. /******************************************************************************
  775. *****************************************************************************/
  776.  
  777. void poss_butt()
  778. {
  779.     reset_poss();
  780.     HideMouse();
  781.     if (!ed_poss)
  782.     {
  783.         ed_last_zone=ed_zone;
  784.         int g=_getplotaction();
  785.         int c=_getcolor();
  786.         _setcolor(5);
  787.         _setplotaction(_GXOR);
  788.         _moveto(260,98);
  789.         _outgtext("x");
  790.         _setcolor(7);
  791.         _moveto(260,98);
  792.         _outgtext("O");
  793.         _setplotaction(g);
  794.         _setcolor(c);
  795.         MouseRelease();
  796.         draw_edteam();
  797.         ed_poss=1;
  798.         draw_edteam();
  799.     }
  800.     else
  801.     {
  802.         ed_last_zone=ed_zone;
  803.         int g=_getplotaction();
  804.         int c=_getcolor();
  805.         _setcolor(7);
  806.         _setplotaction(_GXOR);
  807.         _moveto(260,98);
  808.         _outgtext("O");
  809.         _setcolor(5);
  810.         _moveto(260,98);
  811.         _outgtext("x");
  812.         _setplotaction(g);
  813.         _setcolor(c);
  814.         MouseRelease();
  815.         draw_edteam();
  816.         ed_poss=0;
  817.         draw_edteam();
  818.     }    
  819.     ShowMouse();
  820. }
  821.  
  822. /******************************************************************************
  823. *****************************************************************************/
  824.  
  825. void undo_butt()
  826. {
  827.     HideMouse();
  828.     draw_edteam();
  829.     memcpy(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],undo_tactic,10*2*sizeof(int));
  830.     draw_edteam();
  831.     ShowMouse();
  832.     MouseRelease();
  833. }
  834.  
  835. /******************************************************************************
  836. *****************************************************************************/
  837.  
  838. void init_butt()
  839. {
  840.     HideMouse();
  841.     draw_edteam();
  842.     memset(&(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)]),0,10*2*sizeof(int));
  843.     draw_edteam();
  844.     ShowMouse();
  845.     MouseRelease();
  846. }
  847.  
  848. /******************************************************************************
  849. *****************************************************************************/
  850.  
  851. void copy_butt()
  852. {
  853.     HideMouse();
  854.     draw_edteam();
  855.     memcpy(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],
  856.              ed_tactic[ed_last_zone+((ed_last_zone<32*2) ? ed_last_poss*32:0)],10*2*sizeof(int));
  857.     draw_edteam();
  858.     ShowMouse();
  859.     MouseRelease();
  860. }
  861.  
  862. /******************************************************************************
  863. *****************************************************************************/
  864.  
  865. void swap_butt()
  866. {
  867.     HideMouse();
  868.     draw_edteam();
  869.  
  870. // Store last zone.
  871.     memcpy(temp_tactic,ed_tactic[ed_last_zone+((ed_last_zone<32*2) ? ed_last_poss*32:0)],10*2*sizeof(int));
  872. // Last=current.
  873.     memcpy(ed_tactic[ed_last_zone+((ed_last_zone<32*2) ? ed_last_poss*32:0)]
  874.     ,ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],10*2*sizeof(int));
  875. // current=last.
  876.     memcpy(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],temp_tactic,10*2*sizeof(int));
  877.  
  878.     draw_edteam();
  879.     ShowMouse();
  880.     MouseRelease();
  881. }
  882.     
  883. /******************************************************************************
  884. *****************************************************************************/
  885.  
  886. void e_go_button()
  887. {
  888.     switch(e_button_lit)
  889.     {
  890.         case 1:
  891.         {
  892.             top_l_corn();
  893.             break;
  894.         }
  895.  
  896.         case 2:
  897.         {
  898.             top_r_corn();
  899.             break;
  900.         }
  901.  
  902.         case 3:
  903.         {
  904.             bot_l_corn();
  905.             break;
  906.         }
  907.  
  908.         case 4:
  909.         {
  910.             bot_r_corn();
  911.             break;
  912.         }
  913.         case 5:
  914.         {
  915.             load_butt();
  916.             break;
  917.         }
  918.         case 6:
  919.         {
  920.             save_butt();
  921.             break;
  922.         }
  923.         case 7:
  924.         {
  925.             poss_butt();
  926.             break;
  927.         }
  928.         case 8:
  929.         {
  930.             copy_butt();
  931.             break;
  932.         }
  933.         case 9:
  934.         {
  935.             swap_butt();
  936.             break;
  937.         }
  938.         case 10:
  939.         {
  940.             undo_butt();
  941.             break;
  942.         }
  943.         case 11:
  944.         {
  945.             init_butt();
  946.             break;
  947.         }
  948.         case 12:
  949.         {
  950.             in_game=TRUE;                //return to game.
  951.             break;
  952.         }
  953.         case 13:
  954.         {
  955.             name_butt();
  956.             break;
  957.         }
  958.         case 14:
  959.         {
  960.             home_centre();
  961.             break;
  962.         }
  963.         case 15:
  964.         {
  965.             away_centre();
  966.             break;
  967.         }
  968.     }
  969. }
  970.  
  971. /******************************************************************************
  972. *****************************************************************************/
  973.  
  974. void capture_ed()
  975. {
  976.     int nd=5000;
  977.     int mx=((Mouse.x/2)-8)*8;
  978.     int my=(Mouse.y-8)*8;
  979.     int x,y,d;
  980.     for (int i=0; i<10; i++)
  981.     {
  982.         x=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][0];
  983.         y=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][1];
  984.         x-=mx;
  985.         y-=my;
  986.         d=calc_dist(x,y);
  987.         if (d<nd)
  988.         {
  989.             nd=d;
  990.             picked_up=i+1;
  991.         }
  992.     }
  993. }
  994.  
  995. /******************************************************************************
  996. *****************************************************************************/
  997.  
  998. void move_ed()
  999. {
  1000.     int c=_getcolor();
  1001.     _setcolor(2);
  1002.     int mx=((Mouse.x/2)-8)*8;
  1003.     int my=(Mouse.y-8)*8;
  1004.     int x=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][0];
  1005.     int y=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][1];
  1006.     _setplotaction(_GXOR);
  1007.     char st[3];
  1008.     sprintf(st,"%d",picked_up+1);
  1009.     _moveto(8+(x/8)-3,8+(y/8)-3);
  1010.     HideMouse();
  1011.     _outgtext(st);
  1012.     ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][0]=mx;
  1013.     ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][1]=my;
  1014.     _moveto(8+(mx/8)-3,8+(my/8)-3);
  1015.     _outgtext(st);
  1016.     ShowMouse();
  1017.     _setplotaction(_GPSET);
  1018.     _setcolor(c);
  1019. }
  1020.  
  1021. /******************************************************************************
  1022. *****************************************************************************/
  1023.  
  1024. void pitch_grid()
  1025. {
  1026.     if (picked_up)
  1027.         move_ed();
  1028.     else
  1029.     {
  1030.         capture_ed();
  1031.         MouseYlim(8,107);
  1032.         MouseXlim(8*2,167*2);
  1033.     }
  1034. }
  1035.     
  1036. /******************************************************************************
  1037. *****************************************************************************/
  1038.  
  1039. void e_mouse_fired()
  1040. {
  1041.     if (e_button_lit)
  1042.         e_go_button();
  1043.     else
  1044.     {
  1045.         if ((Mouse.x/2>=200) && (Mouse.x/2<=284)
  1046.             && (Mouse.y>=24) && (Mouse.y<=84))
  1047.             zone_grid();
  1048.         else
  1049.         {
  1050.             if ((Mouse.x/2>=8) && (Mouse.x/2<=168)
  1051.                 && (Mouse.y>=8) && (Mouse.y<=108))
  1052.                 pitch_grid();
  1053.         }
  1054.     }
  1055. }
  1056.  
  1057. /******************************************************************************
  1058. *****************************************************************************/
  1059.  
  1060. /******************************************************************************
  1061. *****************************************************************************/
  1062.  
  1063. // Editor Main...
  1064.  
  1065. void editor_main()
  1066. {
  1067.     
  1068.     _clearscreen(_GCLEARSCREEN);
  1069.     InitMouse();
  1070.     MouseYlim(0,200-4);
  1071.     MouseXlim(0,(320-4)*2);
  1072.     _setplotaction(_GPSET);
  1073.     e_line_border(0,0,320,200,1);    
  1074.     draw_grid();
  1075.     draw_markings();
  1076.     draw_zones();
  1077.     _setcolor(5);
  1078.     e_draw_buttons();
  1079.     _moveto(260,98);
  1080.     _outgtext("x");
  1081.     init_zgrid();
  1082.     write_name();
  1083.     draw_edteam();
  1084.     ShowMouse();
  1085.  
  1086. // Main Loop For Editor...
  1087.  
  1088.     while (!in_game)
  1089.     {
  1090.         ReportMouse();
  1091.         e_process_butts();
  1092.         if (Mouse.b&&1)
  1093.             e_mouse_fired();
  1094.         else
  1095.         {
  1096.             if (picked_up)
  1097.             {
  1098.                 picked_up=0;
  1099.                 MouseYlim(0,200-4);
  1100.                 MouseXlim(0,(320-4)*2);
  1101.             }
  1102.         }
  1103.         delay(50);
  1104.     }    
  1105.     _clearscreen(_GCLEARSCREEN);
  1106.     memcpy(match_tactics1,ed_tactic,(((32*2)+6)*10*2)*sizeof(int));
  1107.     memcpy(match_tactics2,ed_tactic,(((32*2)+6)*10*2)*sizeof(int));
  1108.     MouseRelease();
  1109. }
  1110.  
  1111.